package test;

import java.net.URLEncoder;

import org.junit.Test;

import hyl.core.MyFun;
import hyl.core.fun.MyString;

public class testString {

	// @Test
	public void test() {
		String s = "水电费看见的沙发那边 {1}";

		System.out.println(s.replace("{1}", "程序在不"));
	}

	// @Test
	public void test2() {
		String s = "7,0,1,0,提交成功";
		System.out.println(s.contains("成功"));

	}
	// @Test
	public void test8() {
		String s = "7\\0\\1,0";
		System.out.println(MyFun.htmlEscape(s));
	}
	// @Test
	public void test4_2() {
		String s = "01234567提交成功";
		System.out.println(s.substring(0,0));
		System.out.println(s.substring(0,1));
		System.out.println(MyString.subString(s, 0, 5));
		System.out.println("----");
		System.out.println(s.substring(1,1));
		System.out.println(s.substring(1,2));
		System.out.println(s.substring(1,3));
	}
	// @Test
	public void test3() {
		String s = "7,0,1,0,提交成功";
		System.out.println(s);
		String s1 = URLEncoder.encode(s);
		System.out.println(s1);

		String s2 = URLEncoder.encode(s1);
		System.out.println(s2);
	}

	//@Test
	public void test4() {
		String s = "7,0,1,0,提交成功";
		System.out.println(s.charAt(-1));
	}

	// @Test
	public void test5() {
		String s = "7,0,1,0,提交成功";
		System.out.println(s);
		String[] s1 = s.split(",", -2);
		System.out.println(s1[0]);
		System.out.println(s1[1]);
		System.out.println("-------------");
		String[] s2 = s.split(",", 3);

		System.out.println(s2[0]);
		System.out.println(s2[1]);
		System.out.println(s2[2]);

		String[] s3 = s.split(",", 0);
		System.out.println("-------------");
		System.out.println(s3[0]);
		System.out.println(s3[1]);
	}
	
	//@Test
	public void test6() {
		String s = "79,0,1,0,提交成功";
		int i=MyString.search(s, '成', 0);
		MyFun.print(i,s.charAt(i));
		i=MyString.search(s, '成', -1);
		MyFun.print(i,s.charAt(i));
		System.out.println("--------------");
		i=MyString.search(s, '7', 0);
		MyFun.print(i,s.charAt(i));
		i=MyString.search(s, '7', -1);
		MyFun.print(i,s.charAt(i));
		System.out.println("--------------");
		i=MyString.search(s, '功', 0);
		MyFun.print(i,s.charAt(i));
		i=MyString.search(s, '功', -1);
		MyFun.print(i,s.charAt(i));
		System.out.println("--------------");
		i=MyString.search(s, '成', 0);
		MyFun.print(i,s.charAt(i));
		i=MyString.search(s, '成', -2);
		MyFun.print(i,s.charAt(i));
		
		
	
	}
	
	//@Test
	public void test6_2() {
		String s = "79,0,1,0,提交成功";
		int i=0;
//		System.out.println("--------------");
//		i=MyString.search(s, "提交", 0);
//		MyFun.print(i,s.charAt(i));
//		i=MyString.search(s, "提交", -1);
//		MyFun.print(i,s.charAt(i));
//		System.out.println("--------------");
//		i=MyString.search(s, "成功", 0);
//		MyFun.print(i,s.charAt(i));
//		i=MyString.search(s, "成功", -1);
//		MyFun.print(i,s.charAt(i));
//		System.out.println("--------------");
		i=MyString.search(s, "79,", 0);
		MyFun.print("22",i,s.charAt(i));
		i=MyString.search(s, "79,", -1);
		MyFun.print("33",i,s.charAt(i));
	}
	
	//@Test
	public void test6_1() {
		String s = "79,##0,##1,##0,##提交成功";
		int i=0;
		System.out.println("--------------");
		i=MyString.search(s, "##", 0);
		MyFun.print(i,s.charAt(i+2));
		i=MyString.search(s, "##", -1);
		MyFun.print(i,s.charAt(i+2));
	
	}
	//@Test
	public void test7() {
	System.out.println("ddddd");
		String s = "im123545@@@open=1;@@@ok;";
		System.out.println("---1---");
		MyFun.print(MyFun.split(s, "<]", 0,0)); //ok 分3段 ,先右后左
		MyFun.print(MyFun.split(s, "<]", 0,-1)); //ok 分3段 ,先右后左
		System.out.println("---2---");
		MyFun.print(MyFun.split(s, "@@@", 0,0)); //ok 分3段 ,先右后左
		MyFun.print(MyFun.split(s, "@@@", 0,-1)); //ok 分3段 ,先右后左


	}


	//@Test
	public void test7_1() {
		String s = "im12345@open=1;@ok;@44;";
		System.out.println(s);
		System.out.println();

		MyFun.print(MyFun.split(s, '@', 1,-1)); //ok 分两段 ,先右后左
		MyFun.print(MyFun.split(s, '@', 1,0)); //ok 分两段 ,先左后右	
		System.out.println();
		MyFun.print(MyFun.split(s, '@', 2,-1)); //ok 分3段 ,先右后左
		MyFun.print(MyFun.split(s, '@', 2,0)); //ok 分3段 ,先右后左
		System.out.println();
		MyFun.print(MyFun.split(s, '@', 3,-1)); //ok 分3段 ,先右后左
		MyFun.print(MyFun.split(s, '@', 3,0)); //ok 分3段 ,先右后左
		System.out.println();
		MyFun.print(MyFun.split(s, '@', 0,-1)); //ok 分3段 ,先右后左
		MyFun.print(MyFun.split(s, '@', 0,0)); //ok 分3段 ,先右后左
	}
	//@Test
	public void test7_2() {
		System.out.println();
		String s = "im123545@+open=1;@+ok;@+到时候给;";
		MyFun.print(MyFun.split(s, "@+", 1,-1));//ok 分两段 ,先右后左
		MyFun.print(MyFun.split(s, "@+", 1,0));//ok 分两段 ,先左后右	
		MyFun.print(MyFun.split(s, "@+", 2,-1));//ok 分3段 ,先右后左
		MyFun.print(MyFun.split(s, "@+", 2,0));//ok 分3段 ,先右后左
		MyFun.print(MyFun.split(s, "@+", 3,-1)); //ok 分3段 ,先右后左
		MyFun.print(MyFun.split(s, "@+", 3,0)); //ok 分3段 ,先右后左
		MyFun.print(MyFun.split(s, "@+", 0,-1)); //ok 分3段 ,先右后左
		MyFun.print(MyFun.split(s, "@+", 0,0)); //ok 分3段 ,先右后左
	}
	@Test
	public void test8_1() {
		String s = "im123545@+";
		  System.out.println(String.class.getName() + "@" + Integer.toHexString(System.identityHashCode(s)));
		观察string引用(s)	;
		
	}
	//String 是一个 不可变类型 一旦变化 就是一个新的对象,传参不影响引用
	void 观察string引用(CharSequence sc) {
		String p=(String)sc;
		  System.out.println(String.class.getName() + "@" + Integer.toHexString(System.identityHashCode(p)));
	}
}
